package Testing;

import DeportManage.NotFormatParcelIDException;
import DeportManage.OutRangeOfDaysException;
import DeportManage.ParcelList;
import DeportManage.Parcel;

import org.junit.Test;
import static org.junit.Assert.*;

public class ParcelUnitTest {
	
	@Test (expected = NotFormatParcelIDException.class)
	public void textParcelFormat() throws NotFormatParcelIDException, OutRangeOfDaysException{
		//Parcel ID is X2028, the format is right
		Parcel parcel_1 = new Parcel("X2018",3,3.2,4.6,4.3,2.4);
		//Parcel ID is C2018, the format is right
		Parcel parcel_2 = new Parcel("C2018",3,3.2,4.6,4.3,2.4);
		//Parcel ID is X20189, the format is wrong, because the length of ID is longer than 5 
		Parcel parcel_3 = new Parcel("X20189",3,3.2,4.6,4.3,2.4);
		//Parcel ID is C201, the format is wrong, because the length of ID is shorter than 5 
		Parcel parcel_4 = new Parcel("C201",3,3.2,4.6,4.3,2.4);
		//Parcel ID is R2018, the format is wrong, because the first letter is R
		Parcel parcel_5 = new Parcel("R2018",3,3.2,4.6,4.3,2.4);
		//Parcel ID is %2018, the format is wrong, because the first letter is %
		Parcel parcel_6 = new Parcel("%2018",3,3.2,4.6,4.3,2.4);
		//parcel ID is 42018, the format is wrong, because the first character is 4
		Parcel parcel_7 = new Parcel("42018",3,3.2,4.6,4.3,2.4);
	}
	
	@Test (expected = OutRangeOfDaysException.class)
	public void textParcelDays() throws OutRangeOfDaysException, NotFormatParcelIDException{
		//Days is 1,which meet the requirement
		Parcel parcel_1 = new Parcel("X2018", 1,3.2,4.6,4.3,2.4);
		//Days is 13,which meet the requirement
		Parcel parcel_2 = new Parcel("X2018", 13,3.2,4.6,4.3,2.4);
		//Days is 14, which meet the requirement
		Parcel parcel_3 = new Parcel("X2018", 14,3.2,4.6,4.3,2.4);
		//Days is 15, which out range of days.
		Parcel parcel_4 = new Parcel("X2018", 15,3.2,4.6,4.3,2.4);
		//Days is 24, which out range of days
		Parcel parcel_5 = new Parcel("X2018", 24,3.2,4.6,4.3,2.4);
	}
	
	@Test
	public void testGetID() throws NotFormatParcelIDException, OutRangeOfDaysException {
		String expected1 = "X1234";
		String message1 = "Failed for X1234";
		Parcel p = new Parcel("X1234",12,12.3,2.3,2.4,3.1);
		String actuall = p.getID();
		assertEquals(message1,expected1,actuall);
	}

	@Test
	public void testGetDays() throws NotFormatParcelIDException, OutRangeOfDaysException {
		int expected1 = 12;
		String message1 = "Failed for 12";
		Parcel p = new Parcel("X1234",12,12.3,2.3,2.4,3.1);
		int actuall = p.getDays();
		assertEquals(message1,expected1,actuall);
	}

	@Test
	public void testGetWeight() throws NotFormatParcelIDException, OutRangeOfDaysException {
		String expected1 = String.valueOf(12.3);
		String message1 = "Failed for 12.3";
		Parcel p = new Parcel("X1234",12,12.3,2.3,2.4,3.1);
		String actuall = String.valueOf(p.getWeight());
		assertEquals(message1,expected1,actuall);
	}

	@Test
	public void testGetHeight() throws NotFormatParcelIDException, OutRangeOfDaysException {
		String expected1 = String.valueOf(2.3);
		String message1 = "Failed for 2.3";
		Parcel p = new Parcel("X1234",12,12.3,2.3,2.4,3.1);
		String actuall = String.valueOf(p.getHeight());
		assertEquals(message1,expected1,actuall);
	}

	@Test
	public void testGetWidth() throws NotFormatParcelIDException, OutRangeOfDaysException {
		String expected1 = String.valueOf(2.4);
		String message1 = "Failed for 2.4";
		Parcel p = new Parcel("X1234",12,12.3,2.3,2.4,3.1);
		String actuall = String.valueOf(p.getWidth());
		assertEquals(message1,expected1,actuall);
	}

	@Test
	public void testGetLength() throws NotFormatParcelIDException, OutRangeOfDaysException {
		String expected1 = String.valueOf(3.1);
		String message1 = "Failed for 3.1";
		Parcel p = new Parcel("X1234",12,12.3,2.3,2.4,3.1);
		String actuall = String.valueOf(p.getLength());
		assertEquals(message1,expected1,actuall);
	}

	@Test
	public void testGetDimension() throws NotFormatParcelIDException, OutRangeOfDaysException {
		String expected1 = "3.1 x 2.4 x 2.3";
		String message1 = "Failed for 3.1 x 2.4 x 2.3";
		Parcel p = new Parcel("X1234",12,12.3,2.3,2.4,3.1);
		String actuall = p.getDimension();
		assertEquals(message1,expected1,actuall);
	}
}